package cloudnative.demo.labservice.mapper;


import cloudnative.demo.labservice.model.Device;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DeviceMapper {

    // 查询所有设备
    @Select("SELECT * FROM device")
    List<Device> queryAllDevices();

    // 按工作人员ID查询设备
    @Select("SELECT * FROM device WHERE WorkerID= #{workerId}")
    List<Device> findDevicesByWorkerId(@Param("workerId") Long workerId);

    // 按实验室ID查询设备
    @Select("SELECT * FROM device WHERE DeviceecID= #{deviceId}")
    Device findDevicesByLaboratoryId(@Param("deviceId") Long deviceId);

    // 按实验室ID查询设备
    @Select("SELECT * FROM device WHERE DeviceecID= #{deviceId} AND WorkerID= #{workerId}")
    Device findDevicesByWorkerAndLaboratoryId(@Param("deviceId") Long deviceId,@Param("workerId") Long workerId);

    // 插入新设备
    @Insert("INSERT INTO device (Type, WorkerID, LaboratoryID) VALUES (#{type}, #{workerId}, #{laboratoryId})")
    void addDevice(@Param("type") String type, @Param("workerId") Long workerId, @Param("laboratoryId") Long laboratoryId);

    // 根据ID删除设备
    @Delete("DELETE FROM device WHERE DeviceID = #{deviceId}")
    void deleteDevice(@Param("deviceId") Long deviceId);

    // 更新设备信息
    @Update("UPDATE device SET Type = #{type}, WorkerID = #{workerId}, LaboratoryID = #{laboratoryId} WHERE DeviceID = #{deviceId}")
    void updateDevice(@Param("deviceId") Long deviceId, @Param("type") String type, @Param("workerId") Long workerId, @Param("laboratoryId") Long laboratoryId);
}
